/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        ListNode* cur=head;
        ListNode* pre=NULL;
        if(cur->val==val) return head->next;
        while(cur->next){
            pre=cur;
            cur=cur->next;
            if(cur->val==val)pre->next=cur->next;
            
        }
        if(cur->val==val)pre->next=cur->next;
        return head;
   
    }
};